package draw;

import javax.swing.*;
import java.awt.*;

/**
 * Created with IntelliJ IDEA
 * Description:Graphics学习
 * User:22954
 * Date:2024-03-01
 * Time:0:03
 */
public class Graphics_ extends JFrame {
    Panel panel = null;

    public static void main(String[] args) {
        new Graphics_();
    }

    public Graphics_() {
        panel = new Panel();
        super.add(panel);
        super.setSize(600, 400);
        super.setVisible(true);
        super.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
}

@SuppressWarnings("all")
class Panel extends JPanel {
    /*
    画直线 void drawLine(int x1, int y1, int x2, int y2)
    画矩形边框 void drawRect(int x, int y, int width, int height)
    画椭圆边框 void drawOval(int x, int y, int width, int height)
    填充矩形 void fillRect(int x, int y, int width, int height)
    填充椭圆 void fillOval(int x, int y, int width, int height)
    画图片 boolean drawImage(Image img, int x, int y, ... , ImageObserver observer);
    画字符串 void drawString(String str, int x, int y)
    设置画笔字体 void setFont(Font font)
    设置画笔颜色 void setColor(Color c)
     */
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        //drawLine(int x1, int y1, int x2, int y2)
        g.drawLine(100, 100, 200, 100);
        //drawRect(int x, int y, int width, int height)
        g.drawRect(20, 20, 100, 50);
        //drawOval(int x, int y, int width, int height)
        g.drawOval(0, 0, 150, 50);
        //fillRect(int x, int y, int width, int height)
        g.fillRect(300, 150, 100, 50);
        //void setColor(Color c)  fillOval(int x, int y, int width, int height)
        g.setColor(Color.BLUE);
        g.fillOval(300, 20, 150, 100);
        //drawImage(Image img, int x, int y, ... , ImageObserver observer);
        Image image = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/李燊_2023213588.jpg"));
        g.drawImage(image, 300, 200, 115, 160, this);
        //setFont(Font font)  drawString(String str, int x, int y)
        g.setFont(new Font("微软雅黑",Font.BOLD,30));
        g.setColor(Color.magenta);
        g.drawString("你好",200,180);
    }
}
